package cn.funeralobjects.dictms.web.controller;

import cn.funeralobjects.common.service.*;
import cn.funeralobjects.common.web.controller.*;
import cn.funeralobjects.common.web.controller.converter.ModelMapper;
import cn.funeralobjects.dictms.entity.EDictRelate;
import cn.funeralobjects.dictms.model.DictRelate;
import cn.funeralobjects.dictms.service.DictRelateService;
import cn.funeralobjects.dictms.web.api.DictRelateApi;
import cn.funeralobjects.dictms.web.mapper.DictRelateMapper;
import cn.funeralobjects.dictms.web.model.MDictRelate;
import cn.funeralobjects.dictms.web.model.VDictRelate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author FuneralObjects
 * Create date: 2020/6/9 2:39 PM
 */
@RestController
@RequestMapping("/dict-relate")
public class DictRelateController implements DictRelateApi,
        CommonModifyController<VDictRelate, MDictRelate, DictRelate, EDictRelate, Integer>,
        RestEntityController<VDictRelate, EDictRelate, Integer>,
        RestCodeController<VDictRelate, EDictRelate, Integer>,
        RestEnableController<VDictRelate, EDictRelate, Integer>,
        RestCommitController<Integer> {
    @Resource
    private DictRelateService dictRelateService;

    @Resource
    private DictRelateMapper dictRelateMapper;


    @Override
    public ModelMapper<MDictRelate, DictRelate, EDictRelate, VDictRelate> modelMapper() {
        return dictRelateMapper;
    }

    @Override
    public CommonModifyService<DictRelate, EDictRelate, Integer> commonModifyService() {
        return dictRelateService;
    }

    @Override
    public CodeService<EDictRelate, Integer> codeService() {
        return dictRelateService;
    }

    @Override
    public CommitService<Integer> commitService() {
        return dictRelateService;
    }

    @Override
    public EnableService<EDictRelate, Integer> enableService() {
        return dictRelateService;
    }

    @Override
    public EntityService<EDictRelate, Integer> entityService() {
        return dictRelateService;
    }

    @Override
    public IdService<Integer> idService() {
        return dictRelateService;
    }

    @Override
    public DictRelate toModify(MDictRelate vo) {
        return new DictRelate()
                .setDepth((short) vo.getRule().size())
                .setHeadDictId(vo.getRule().get(0))
                .setCode(vo.getCode())
                .setRule(vo.getRule())
                .setRemark(vo.getRemark());
    }
}
